package py.org.atom.seam;

import org.jboss.seam.annotations.In;
import org.jboss.seam.faces.FacesMessages;
import org.jboss.seam.international.Messages;
import org.jboss.seam.international.StatusMessage.Severity;

import py.org.atom.seam.util.Sys;

public class Base {

    @In 
    protected FacesMessages facesMessages;
	
    
	protected void info(String key){
    	String msg = Messages.instance().get(key);
    	this.facesMessages.add(Severity.INFO, msg);    	
    }
    
    protected void warn(String key){
    	String msg = Messages.instance().get(key);
    	this.facesMessages.add(Severity.WARN, msg);    	
    }

    protected void error(String key){
    	String msg = Messages.instance().get(key);
    	this.facesMessages.add(Severity.ERROR, msg);    	
    }	
	
    protected void error(Exception e){
    	String key = Sys.property("prefix") + ".error.Internal";
    	String msg = Messages.instance().get(key);
    	this.facesMessages.add(Severity.ERROR, msg + e.getCause());     	
    }
    
	public String getPrivLabel(char in){
		String prefix = Sys.property("prefix");
		String label = Messages.instance().get(prefix + ".priv." + in);
		
		return label;
	}

	public String getPrivLabel(char in, String obj){
		String prefix = Sys.property("prefix");
		String label = Messages.instance().get(prefix + ".priv." + obj + "." +in);
		
		if(label.equals(prefix + ".priv." + obj + "." +in))
			label = null;
		
		if(label == null)
			label =  Messages.instance().get(prefix + ".priv." +in);
		
		return label;
	}	
	
    public String getPrivLabel(String privs){
    	String out = "| ";
    	for(int i=0; i<privs.length(); i++){
    		char c = privs.charAt(i);
    		out += this.getPrivLabel(c) + " | ";
    	}
    	return out;
    }

    public String getPrivLabel(String privs, String obj){
    	String out = "| ";
    	for(int i=0; i<privs.length(); i++){
    		char c = privs.charAt(i);
    		out += this.getPrivLabel(c,obj) + " | ";
    	}
    	return out;
    }    
    
}
